// pages/my-balance/my-balance.js
import { Balance } from '../../../models/balance'
const balance = new Balance()
import {check} from '../../../util/identityCheck'

Page({

  data: {
    show: false,
    myBalance: 0,
    number: 0,
    id: 0,
    actions: [
      {
        name: '微信'
      },
      {
        name: '支付宝'
      }
    ],
    title: '请选择提现方式'
  },

  onLoad: function (options) {
    console.log('我的余额执行');
    if(!check())return
    this.withdrShow()
  },

  withdrShow () {
    balance.withdrShow({
    }, res => {
      this.setData({
        myBalance: res.account_balance
      })
    })
  },

  withdrawal () {
    balance.withdrawal({
      type: 1,
      account_id: this.data.id || 0,
      amount: this.data.number
    })
  },

  withdrawalAll () {
    this.setData({
      number: this.data.myBalance
    })
  },

  publish () {
    if (!this.data.myBalance) {
      wx.showToast({
        title: '余额不足',
        icon: 'none'
      })
      return
    }
    if (this.data.number > this.data.myBalance) {
      wx.showToast({
        title: '可提现余额不足',
        icon: 'none'
      })
      return
    }
    this.withdrawal()
  },

  input (event) {
    this.setData({
      number: event.detail.value
    })
  },

  onClose () {
    this.setData({
      show: false
    })
  },

  showPopup () {
    wx.navigateTo({
      url: '/pages/ali-withdrawal/ali-withdrawal'
    })
  }
})
